package org.uncas.homepage.client.widgets;

import java.util.List;

import org.uncas.homepage.client.services.PicasaService;
import org.uncas.homepage.client.services.PicasaServiceAsync;
import org.uncas.homepage.client.valuobject.PicasaAlbumData;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;

public class PicasaAlbumWidget extends Composite {

	private int numberOfAlbums;
	private final Grid grid;
	
	public PicasaAlbumWidget(int numberOfAlbums) {
		this.numberOfAlbums = numberOfAlbums;
		grid = new Grid(1,3);
//		setWidth("200px");
		initWidget(grid);
//		grid.setWidth("100px");
//		grid.setHeight("100px");
//		setWidth("100px");
//		setHeight("100px");
//		setPixelSize(100, 100);
//		setWidth("90%");
	}

	protected void onLoad() {
		System.out.println("Onload picasaalbumwidget");
//		grid.setWidget(0, 0, new HTML("After load"));
//		
//		PicasaServiceAsync picasaService = (PicasaServiceAsync) GWT.create(PicasaService.class);
//		
//		ServiceDefTarget endpoint = (ServiceDefTarget) picasaService;
//		String moduleRelativeURL = GWT.getModuleBaseURL() + "picasa";
//		System.out.println("Onload picasaalbumwidget:"+moduleRelativeURL);
//		endpoint.setServiceEntryPoint(moduleRelativeURL);
//		
//		AsyncCallback callback = new AsyncCallback() {
//			public void onSuccess(Object result) {
//				System.out.println("Onsuccess");
//				List list = (List)result;
//				for (int i=0;i<list.size();i++) {
//					grid.setHTML(0, i, ((PicasaAlbumData)list.get(i)).getHtmlString());
//					grid.getCellFormatter().setWidth(0, i, "100px");
//				}
//			}
//		    public void onFailure(Throwable caught) {
//		    	//text.setText("On failure!");
//		    }
//		};
//		picasaService.getLastAlbums(numberOfAlbums,callback);		
		
		super.onLoad();
	}
	
	
}
